#ifndef COMMON
#define COMMON

#include<sys/types.h>

//Client
extern const u_int16_t CLIENT_ACEP_PORT;
extern const u_int16_t CLIENT_SEND_PORT;

//Server
extern const u_int16_t SERVER_ACEP_PORT;
extern const char* SERVER_IP_ADDR;
extern const u_int32_t LISTEN_BACK_LOG;
extern const u_int32_t MAX_EVENTS_NUM;
extern const u_int32_t MAX_USER_NUM;


//User
#define USER_NAME_LEN 20
#define INFO_LEN 40



//Game
extern const int BATTLE_INIT_HP;

typedef enum ACTION{
    READY,
    STONE,//石头
    SCISSOR,//剪刀
    CLOTH//布
}ACTION;

#define EXIT_MSG 0x00 //服务器处理
#define REGISTER_MSG 0x01//服务器处理
#define REGISTER_RPY 0x02//客户端处理
#define USER_ONLINE_MSG 0X03//客户端处理
#define USER_OFFLINE_MSG 0x04//客户端处理
#define MAKE_FRIEND_MSG 0x05//服务器+客户端处理
#define MAKE_FRIEND_REPLY 0x06//服务器+客户端处理
#define BATTLE_REQUEST_MSG 0x07//服务器+客户端处理
#define BATTLE_REQUEST_RPY 0x08//服务器+客户端处理
#define BATTLE_MSG 0x09//服务器处理
#define BATTLE_STOP_MSG 0x0a//服务器+客户端处理
#define BATTLE_RESULT_MSG 0x0b//客户端处理
#define ERR_MSG 0x0c//客户端+服务器


typedef struct Message{
    u_int8_t type;
    char content[127];
}Message;

typedef struct ExitMsg{
    char info[INFO_LEN+1];
}ExitMsg;

typedef struct RegisterMsg{
    char name[USER_NAME_LEN+1];
}RegisterMsg;

typedef struct RegisterRpy{
    u_int8_t is_successed;
    char info[INFO_LEN+1];
}RegisterRpy;

extern const char* REGISTER_NAME_REPEATED_INFO;
extern const char* REGISTER_SESSION_EXIST_INFO;

typedef struct OnlineMsg{
    char name[USER_NAME_LEN+1];
}OnlineMsg;

typedef struct OfflineMsg{
    char name[USER_NAME_LEN+1];
}OfflineMsg;

typedef struct MakeFriendMsg{
    char user_name[USER_NAME_LEN+1];
    char friend_name[USER_NAME_LEN+1];
}MakeFriendMsg;

typedef struct MakeFriendRpy{
    u_int8_t is_success;
    char user_name[USER_NAME_LEN+1];
    char info[INFO_LEN+1];
}MakeFriendRpy;

extern const char* USER_OFFLINE_INFO;
extern const char* FRIEND_ADDED_INFO;

typedef struct BattleRequestMsg{
    char user_name[USER_NAME_LEN+1];
    char enemy_name[USER_NAME_LEN+1];
}BattleRequestMsg;

typedef struct BattleRequestRpy{
    u_int8_t is_seccess;
    char user_name[USER_NAME_LEN+1];
    char info[INFO_LEN+1];
}BattleRequestRpy;


typedef struct  BattleMsg{
    char user_name[USER_NAME_LEN+1];
    ACTION action;
}BattleMsg;

typedef struct BattleResultMsg{
    char winner[USER_NAME_LEN+1];
}BattleResultMsg;

typedef struct BattleStopMsg{
    char stopinfo[INFO_LEN];
}BattleStopMsg;
extern const char* BATTLE_CLOSE_INFO;

//Common
extern void make_nonblocking(int fd);

extern int send_msg(int sockfd,Message msg);

#endif